import 'package:flutter/material.dart';

class BlockTest extends StatefulWidget {
  @override
  _BlockTestState createState() => _BlockTestState();
}

class _BlockTestState extends State<BlockTest>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('传值测试'),
      ),
      body: Center(
        child: new RaisedButton(
          onPressed: () {
            //Navigator.of(context).pop('1111111-111111');
            //print(jiantou('张三'));
            // kexuancanshucanshu('张三',age: 10);
            // kexuancanshuweizhi('李四',10);
            // morencanshu('马武');

            // List list = ['a','b','c','d','e'];
            // List newlist = listTimes(list, times);
            // print(newlist);

            // nimingfangfa();
            // var list1 = ['a','b','c','d','e','f'];
            // var result = listTimes(list1, (str){return str*3;});
            // print(result);

            // var list2 = ['1','2','3','4','5'];
            // print(listTimesniming(list2));
            // var func = bibao();
            // func();
            // func();
            var rect = area();
            rect.width = 20;
            rect.height = 30;
            print(rect.areaResult());
            var a ;
            var b = 20;
            print(a ?? b);
          },
          child: Text('点击返回'),
        ),
      ),
    );
  }

  void printTest() {
    var list = [1, 2, 3, 4];
    print(list.asMap());

    List list1 = [9, 8, 7, true];
    print(list1);
    List list2 = [0, 1, 2, 2, 2, 2];
    list2.forEach(print);
  }

  //=>就相当于{}
  jiantou(String name) => '我叫$name';

  //可选参数
  //基于参数{}
  kexuancanshucanshu(String name, {int age, String gander}) =>
      print('我叫$name,我今年$age岁了,我是$gander的');
  //基于位置[]
  kexuancanshuweizhi(String name, [int age, String gander]) =>
      print('我叫$name,我今年$age岁了,我是$gander的');
  //默认参数
  morencanshu(String name, {int age = 0, String gander = '男'}) =>
      print('我叫$name,我今年$age岁了,我是$gander的');
  //dart中方法也是对象，可以当做参数
  List listTimes(List list, String time(str)) {
    for (var i = 0; i < list.length; i++) {
      list[i] = time(list[i]);
      print(list[i]);
    }
    return list;
  }

  String times(str) {
    return str * 3;
  }

  List listTimesniming(List list) {
    var func = (str) {
      return str * 3;
    };
    for (var i = 0; i < list.length; i++) {
      list[i] = func(list[i]);
      print(list[i]);
    }
    return list;
  }

  nimingfangfa() {
    var func = (str) {
      print('hello--$str');
    };
    func('word');
    (() {
      print('----');
    })();
  }
}

bibao() {
  int a = 0;
  printBibaoA() {
    print(a++);
  }

  return printBibaoA;
}

nimingbibao() {}
//dart中 方法不能重载

//面积
class area {
  num width, height;
  areaResult() {
    return width * height;
  }
}
backios(){
  
}
